package com.example.administrator.myapplication.Util;

import android.graphics.Bitmap;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.ImageView;
import com.bumptech.glide.request.target.ImageViewTarget;

/**
 * Created by Administrator on 2019/6/20 0020.
 */

public class TransformationUtils extends ImageViewTarget<Bitmap> {
    private ImageView target;
    public TransformationUtils(ImageView target) {
        super(target);
        this.target = target;
    }
    @Override
    protected void setResource(Bitmap resource) {
        view.setImageBitmap(resource);
        //获取原图的宽高
        int width = resource.getWidth();
        int height = resource.getHeight();
        Log.e("原图的宽为:",String.valueOf(width));
        Log.e("原图的高为:",String.valueOf(height));
        //获取imageView的宽
        int imageViewWidth = target.getWidth();
        //计算缩放比例
        float sy = (float)imageViewWidth/(float)width;
        //计算图片等比例放大后的高
        int imageViewHeight = (int)(height * sy);
        Log.e("imageview宽为:",String.valueOf(imageViewWidth));
        Log.e("修正后图片的高为:",String.valueOf(imageViewHeight));
        ViewGroup.LayoutParams params = target.getLayoutParams();
        params.height = imageViewHeight;
        target.setLayoutParams(params);
    }
}
